package com.eaoa.uc.permission.bo;

import java.util.List;
import java.util.Set;

import com.eaoa.base.EABaseBusinessObject;
import com.eaoa.dao.pub.PubAccountDAO;
import com.eaoa.vo.pub.PubAccount;
import com.eaoa.vo.pub.PubRole;

public class RoleRemoveAccountBO extends EABaseBusinessObject{
	private static PubAccountDAO accountDAO = new PubAccountDAO(); 
	private Long accountno;
	private List rolenos;
	
	public RoleRemoveAccountBO(Long accountno, List rolenos) {
		super();
		this.accountno=accountno;
		this.rolenos = rolenos;
	}
	
	@Override
	protected void performBusinessLogic() {
		PubAccount account = (PubAccount)accountDAO.loadAndLock(accountno);
		Set roles = account.getPubRoles();
		for(int i=0 ; i<rolenos.size(); i++){
			Long roleno = (Long)rolenos.get(i);
			PubRole role = new PubRole(roleno);
			if(roles.contains(role)){
				roles.remove(role);
			}
			
		}
		account.setPubRoles(roles);
		accountDAO.update(account);
		
	}
}